/*
 * @lc app=leetcode id=485 lang=cpp
 *
 * [485] Max Consecutive Ones
 */

// @lc code=start
class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int ans = 0;
        nums.push_back(0);
        int n = nums.size();
        int j = -1;
        for (int i = 0; i < n; ++i) {
            if (nums[i] == 1) {
                if (j == -1) {
                    j = i;
                }
            } else {
                if (j != -1) {
                    ans = std::max(i - j, ans);
                }
                j = -1;
            }
        }
        return ans;
    }
};
// @lc code=end

